<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\common\model\learn\article;

use cores\BaseModel;

/**
 * 题目模型
 * Class Category
 * @package app\common\model
 */
class CategoryUser extends BaseModel {
	// 定义表名
	protected $name = 'learn_article_category_user';
	// 定义主键
	protected $pk = 'category_id';

	// 追加字段
	protected $append = ['percent'];

	public function getPercentAttr($value, $data) {
		$percent = round($data['complate_num'] / $data['total_num'] * 100, 2);
		return $percent;
	}

	public function book() {
		$module = self::getCalledModule();

		return $this->hasOne("app\\{$module}\\model\\learn\\ArticleCategory", 'category_id', 'book_id');
	}
	/**
	 * 分类详情
	 * @param int|array $where
	 * @param array $with
	 * @return static|array|null
	 */
	public static function detail($where, array $with = []) {
		return static::get($where, $with);
	}

}
